//
//  SSSPersonalPointsViewCell.m
//  SSSMerchant
//
//  Created by xnxin on 2017/3/22.
//  Copyright (c) 2017 xnxin. All rights reserved.
//

#import "SSSPersonalPointsViewCell.h"
#import "SSSPersonalPointsViewCellModel.h"
#import "NSDateAddition.h"
#import "NSNumber+Addition.h"


@interface SSSPersonalPointsViewCell()

@property (readonly) SSSPersonalPointsViewCellModel *model;

@end

@implementation SSSPersonalPointsViewCell
@dynamic model;

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (!self) {
        return nil;
    }

    [self initializeUI];
    [self makeConstraints];
    self.graylineEdgeInset = UIEdgeInsetsMake(0, 12, 0, 12);

    return self;
}
- (void)initializeUI {

    self.dateLabel = [UILabel new];
    self.dateLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];
    self.dateLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.dateLabel];

    self.sourceTypeLabel = [UILabel new];
    self.sourceTypeLabel.textColor = self.dateLabel.textColor;
    self.sourceTypeLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.sourceTypeLabel];

    self.userNameLabel = [UILabel new];
    self.userNameLabel.font = [UIFont systemFontOfSize:15];
    self.userNameLabel.textColor = UIColor.blackColor;
    [self.contentView addSubview:self.userNameLabel];

    self.moneyLabel = [UILabel new];
    self.moneyLabel.font = [UIFont systemFontOfSize:15];
    self.moneyLabel.textColor = UIColor.blackColor;
    [self.contentView addSubview:self.moneyLabel];

    self.ratioLabel = [UILabel new];
    self.ratioLabel.numberOfLines = 0;
    self.ratioLabel.font = [UIFont systemFontOfSize:11];
    self.ratioLabel.textColor = UIColor.blackColor;
    self.ratioLabel.backgroundColor = [UIColor colorWithHex:@"F6F6F6"];
    self.ratioLabel.layer.cornerRadius = 5;
    self.ratioLabel.layer.masksToBounds = true;
    self.ratioLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.ratioLabel];
}


- (void)makeConstraints {

    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.contentView.mas_top).offset(12);
        make.leading.equalTo(self.contentView.mas_leading).offset(12);
    }];

    [self.sourceTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.dateLabel.mas_centerY);
        make.leading.equalTo(self.dateLabel.mas_trailing).offset(10);
    }];

    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.leading.equalTo(self.dateLabel.mas_leading);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-9);
    }];

    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userNameLabel.mas_centerY);
        make.centerX.equalTo(self.contentView.mas_centerX);
    }];

    [self.ratioLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-12);
        make.height.equalTo(@(35));
        make.width.equalTo(@(56));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-5);
    }];
}

- (void)setModel:(SSSPersonalPointsViewCellModel *)model {
    _model = model;

    self.dateLabel.text = [model.date xhstringWithFormat:@"yyyy-MM-dd HH:mm"];
    self.sourceTypeLabel.text = [NSString stringWithFormat:@"%ld", (long)model.sourceType];
    self.userNameLabel.text = model.username;
    self.moneyLabel.text = model.money.moneyValue;
    self.ratioLabel.text = [NSString stringWithFormat:@"上传比例\n%d%%", model.percent];

}
@end
